package com.gxa.autoparts.portal.controller;

import com.gxa.autoparts.core.common.JsonResult;
import com.gxa.autoparts.core.pojo.GoodsCollectionVo;
import com.gxa.autoparts.core.util.ThreadLocalUtil;
import com.gxa.autoparts.portal.mapper.UserCollectionMapper;
import com.gxa.autoparts.portal.service.UserCollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/userCollection")
@Api(tags = "用户收藏")
public class UserCollectionController {

    @Autowired
    UserCollectionService userCollectionService=null;

    @PostMapping("/findUserCollection")
    @ApiOperation("查询用户收藏商品")
    public Map findAll(){
        List<Map> all = userCollectionService.findAll(1L);
        //Object o = ThreadLocalUtil.get();
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(all);
        return jsonResult.getDataMap();

    }
    @PostMapping("/updateUserCollection")
    @ApiOperation("编辑商品(取消收藏)")
    public Map update(@RequestBody List<Long> list){

        userCollectionService.update(list);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getDataMap();

    }

    @PostMapping("/addCollection")
    @ApiOperation("收藏商品")
    public Map add(@RequestParam("goodsId") Long goodsId){
        userCollectionService.add(1L,goodsId);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getDataMap();

    }
}
